import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-10-30
 * Time: 19:44
 */
public class test_2 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            int ret = 0;
            for (int i = a; i <= b; i++) {
                boolean flag = magicNumber(i);
                if (flag) {
                    ret++;
                }
            }
            System.out.println(ret);
        }
    }

    public static boolean magicNumber(int n) {
        String s = Integer.toString(n);
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < s.length(); j++) {
                if (i != j && s.charAt(i) != '0' && s.charAt(j) != '0') {
                    String str = s.charAt(i) + "" + s.charAt(j);
                    if (isPrime(Integer.parseInt(str))) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public static boolean isPrime(int n) {
        //n<=3时，质数有2和3
        if (n <= 3) {
            return n > 1;
        }
        //当n>3时，质数无法被比它小的数整除
        for (int i = 2; i < n; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}
